<template>
<div class="export-div" style="text-align:right;padding-top: 10px;padding-right: 20px;">
  <!--<el-button type="primary" v-show="enableExportExcel" @click="exportExcel">导出Excel</el-button>-->
  <i class="el-icon-download" v-show="enableExportExcel" @click="exportExcel" style="font-size: 20px;
    cursor: pointer;
    border-radius: 50%;
    background-color: #888;
    padding: 5px;
    font-weight: bold;
    color: #fff;"></i>
</div>
</template>

<script>
import {
  exportExcel,
  downloadExcelUrl
} from '@/server/initiatingprocess';


export default {
  methods: {
    
    exportExcel(){
      /* 导出Excel参数 */
      var query = this.$route.query
      var formInstId = query.formInstId
      var formServiceName = query.formServiceName
      var isHive = query.isHive

      const loading = this.$loading({
          lock: true,
          text: '正在导出...',
          spinner: 'el-icon-loading'
        });
      exportExcel({formInstId:formInstId, formServiceName: formServiceName, isHive: isHive, moduleName: this.moduleName, fileName: this.fileName})
        .then(response => {
          loading.close();
          if(response.code==1){
            var filePath = response.data.datas[0].filePath;
            var fileName = response.data.datas[0].fileName;
            window.location = downloadExcelUrl+'?filePath='+filePath+'&fileName='+fileName;
          }else{
            this.$message.error(response.message);
          }
        })
        .catch(error => {
          loading.close();
          this.$message.error(error.message);
        })
    }
  },
  props: {
    moduleName: {
      type: String,
      required: true
    },
    fileName: {
      type: String,
      required: true
    }
  },

  
  data() {
    console.log('query:',this.$route.query)
    console.log('moduleName:',this.moduleName)
    var enableExportExcel = !!this.$route.query.formInstId
    return {
      enableExportExcel: enableExportExcel
    }
  },
}
</script>

<style lang="scss">
.fixedform {
    
}
</style>
